<template>
  <el-dialog title="数据获取" :visible.sync="visible" width="800px" top="5vh" append-to-body>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
      <el-form-item label="名称" prop="dict_label">
        <el-input v-model="queryParams.dict_label" placeholder="名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="数值" prop="dict_value">
        <el-input v-model="queryParams.dict_value" placeholder="请输入数值" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row>
      <el-table @row-click="clickRow" ref="table" :data="dataList" @selection-change="handleSelectionChange"
        height="260px">
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column label="名称" prop="dict_label" :show-overflow-tooltip="true" />
        <el-table-column label="数值" prop="dict_value" :show-overflow-tooltip="true" />
        <el-table-column label="参数1" prop="param1" :show-overflow-tooltip="true" />
        <el-table-column label="参数2" prop="param2" :show-overflow-tooltip="true" />
        <el-table-column label="参数3" prop="param3" :show-overflow-tooltip="true" />
      </el-table>
      <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList" />
    </el-row>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="handleSelectd">确 定</el-button>
      <el-button @click="visible = false">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import {
    dictSelect
  } from "@/api/system/dict/type";
  export default {
    name: "dictSelect",
    // dicts: ['sys_normal_disable'],
    // props: {
    //   pd: {
    //     dict_type
    //   }
    // },
    data() {
      return {
        // 遮罩层
        visible: false,
        // 选中数组值
        dictrow: [],
        // 总条数
        total: 0,
        // 未授权用户数据
        dataList: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          dict_type: undefined,
          dict_label: undefined,
          dict_value: undefined
        }
      };
    },
    methods: {
      // 显示弹框
      show(dictParams) {
        this.queryParams = dictParams;
        this.getList();
        this.visible = true;
      },
      clickRow(row) {
        this.$refs.table.toggleRowSelection(row);
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.dictrow = selection;
      },
      // 查询表数据
      getList() {
        dictSelect(this.queryParams).then(res => {
          this.dataList = res.data;
          this.total = res.total;
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      /** 选择授权用户操作 */
      handleSelectd() {
        if(this.dictrow == null || this.dictrow==0){
            this.$notify({
                title:'提示',
                type:'warning',
                message: '请至少选择一条数据!'
            });
            return;
        }
        this.$emit('onDictSelectd',this.dictrow);
        this.visible = false;


        // const roleId = this.queryParams.roleId;
        // const userIds = this.userIds.join(",");
        // if (userIds == "") {
        //   this.$modal.msgError("请选择要分配的用户");
        //   return;
        // }
        // authUserSelectAll({ roleId: roleId, userIds: userIds }).then(res => {
        //   this.$modal.msgSuccess(res.msg);
        //   if (res.code === 200) {
        //     this.visible = false;
        //     this.$emit("ok");
        //   }
        // });
      }
    }
  };
</script>
